package com.example.passport.controller;

import com.example.common.dto.JsonResult;
import com.example.passport.dto.MenuSearchDto;
import com.example.passport.dto.MenuUpdateDto;
import com.example.passport.entity.Menu;
import com.example.passport.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "菜单管理")
@RestController
@CrossOrigin
@RequestMapping("/passport/menu")
public class MenuController {
    @Resource
    MenuService menuService;

    @ApiOperation("获取菜单列表")
    @GetMapping("/list")
    public JsonResult<List<Menu>> list(MenuSearchDto menu) {
        return new JsonResult<>(menuService.findMenu(menu));
    }

    @ApiOperation("获取菜单列表")
    @GetMapping("/listAll")
    public JsonResult<List<Menu>> listAll() {
        return new JsonResult<>(menuService.findAll());
    }

    @ApiOperation("获取角色对应的菜单")
    @GetMapping("/listId")
    public JsonResult<List<Long>> listId(Long roleId) {
        return new JsonResult<>(menuService.findId(roleId));
    }

    @ApiOperation("(新增/修改)角色和菜单关系")
    @PostMapping("/update")
    public JsonResult<String> update(MenuUpdateDto menuUpdateDto) {
        menuService.update(menuUpdateDto);
        return new JsonResult<>();
    }

}
